package de.koller.oceanFramework.plain;

import de.koller.oceanFramework.OceanException;
import java.awt.Image;
import java.io.InputStream;
import javax.imageio.ImageIO;

/**
 * 
 * @author Fabian Koller
 */
public class ImageBuffer extends Buffer<Image> {

	/**
	 * 
	 * @param name
	 * @return
	 */
	@Override
	protected Image loadValue( String name ) {
		ClassLoader cl = this.getClass().getClassLoader();
		InputStream in = cl.getResourceAsStream( name );
		
		try {
			return ImageIO.read( in );
		} catch( Exception ex ) {
			throw new OceanException( ex );
		}
	}

	@Override
	public long getEstimatedSize() {
		long b = 0;
		for( Image img : buffer.values() )
			b += img.getWidth( null ) * img.getHeight( null ) * 4;
		return b;
	}
	
}
